support query-based terms lookup queries in DLS#6244
Conversation
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit 6a67442.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
PR Reviewer Guide 🔍(Review updated until commit 6a67442)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 6a67442 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit d84e39e
Suggestions up to commit dd84988
Suggestions up to commit 55eb985
Suggestions up to commit a8dcab5
Suggestions up to commit ab9eb03
|
faeba2f to
ab9eb03
Compare
|
Persistent review updated to latest commit ab9eb03 |
ab9eb03 to
a8dcab5
Compare
|
Persistent review updated to latest commit a8dcab5 |
|
the CI failure is a false reject (can't fetch maven snapshots). i've seen this happen a lot lately! |
|
CC @srikanthpadakanti (you implemented |
|
from what i can see all CI failures are false rejects: they either failed due to not being able to fetch maven artefacts (i've seen that a lot now on PRs on this repo - what's going on here?) - or completely unrelated tests failing => probably nothing that i can help sort out here? |
a8dcab5 to
55eb985
Compare
|
Persistent review updated to latest commit 55eb985 |
55eb985 to
dd84988
Compare
|
Persistent review updated to latest commit dd84988 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6244 +/- ##
==========================================
+ Coverage 75.10% 75.20% +0.10%
==========================================
Files 451 451
Lines 29275 29276 +1
Branches 4416 4419 +3
==========================================
+ Hits 21987 22018 +31
+ Misses 5259 5212 -47
- Partials 2029 2046 +17
🚀 New features to boost your workflow:
|
|
Thank you for this and sorry for the late response; at the moment, I have quite a few different things going on. |
|
if we can't reach an understanding of how the whitelisting for the index targeted by the subquery should work before we hit the code freeze for 3.8.0 would it also be ok if i'd split this in two: this PR would only add support for running query-based TLQs in DLS and the authorization part would be a new issue. then it'd already be possible to use query-based TLQ in DLS as long as the user is granted read access to the index targeted by the subquery (a workable workaround which could be documented as such). |
dd84988 to
d84e39e
Compare
|
Persistent review updated to latest commit d84e39e |
|
the CI failure seems to be an infrastructure issue. i've reported it on slack. |
I think I cleared everything out for myself, just to summarize for others, we do have:
Thanks @rursprung for patience, I just have one minor comment to update the comments section, attributing settings call, LGTM otherwise! |
OpenSearch introduced the possibility to use a `query` rather than just an `id` in Terms Lookup Queries in OpenSearch#18195 in release 3.2.0. However, support for this was never added to the security plugin for DLS/FLS. When trying to use `query` based TLQ in a DLS this failed for two reasons: - the visible failure is an NPE because `DlsFilterLevelActionHandler` unconditionally dereferenced `termsLookup().id()`, which returns `null` for query-based lookups. - additionally, the `DocumentAllowList` privilege bypass only handled `GetRequest`, but query-based TLQ internally resolves via `SearchRequest` and additionally uses a `GetSettingsRequest`, causing the privileges evaluator to block the lookup even after the NPE is fixed. This commit adds proper support for `query` based TLQ in DLS, both for the old and the new evaluator, by allowlisting a wildcard entry for the whole index in question rather than a single document in case `query` is used. additionally, `SearchRequest` and `GetSettingsRequest` are now also supported in `DocumentAllowList#isAllowed`. Furthermore, the legacy `PrivilegesEvaluatorImpl#checkDocAllowListHeader` now delegates to `DocumentAllowList#isAllowed` since the old method body was a hand-inlined copy of the same logic (parse header, check request); delegating removes the duplication and picks up `SearchRequest` support without repeating the new code. Header parsing in `DocumentAllowList#isAllowed` is now delegated to `DocumentAllowList#get` to centralise error handling. The wildcard allowlist pattern is already established for Dashboards multi-tenancy and is scoped to the request's thread context, so it cannot grant persistent or write access beyond the TLQ resolution. Existing code with the wildcard has been migrated to use the new constant to make it easier to find it. fixes opensearch-project#6243 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
so far, the tests only used the legacy evaluator. add a new subclass to also test against V4 to ensure that this is also covered. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
d84e39e to
6a67442
Compare
|
thanks @reta! i've incorporated your feedback & rebased the PR. is there a need to raise a docs request for this at all? the docs already state that TLQ is supported in DLS and didn't state anywhere that |
|
Persistent review updated to latest commit 6a67442 |
Thanks @rursprung , I think no need for doc changes, this is indeed an oversight (== bugfix), thanks! |
|
@reta: is there anything missing to get this merged before the code freeze? CI is happy and i see an approval on the PR (i'm not a maintainer, so i don't have the rights to hit merge) |
|
@reta I don't have any objections, but I do think our coverage of FGAC for TLQs is lacking in general. I think this change looks sensible to me, and separately I would also like someone to take on adding FGAC focused tests for TLQs since you can "join" with another index. I certainly hope the subquery is being executed within the same context as the top level search. |
|
@rursprung additionally I would like to see coverage in scenarios where the TLQ is done on an index where the user has DLS/FLS restrictions. I haven't dug deep on this, but I don't think this repo has a lot of coverage in this feature that was added in 3.2. |
@cwperks but that's in |
Ah, my bad. I'm glad we have tests in place for a number of scenarios already. At a glance, this seemed like an area that could have issues given that it can link to another index to query and the user running the query on the primary index may have restrictions on the second index. In that event, I wanted to make sure the restrictions applied, either if it is getting by id or doing a search to find terms to replace in the primary query. |
|
ah, my bad. now i see what you're looking for: the TLQ on another index which is itself protected by DLS. yes, i think that's not currently covered by tests. IIUC there is one caveat here (and i wasn't aware of this for a long time and i don't think that it's clearly documented?): the DLS is executed as a wrapper around the main query, i.e. this becomes one big query in the end. thus the restriction is also lifted for the wrapped query. though i haven't tried that yet. since i'm off now i won't be able to update this PR until i get back. i leave it up to you if you want to merge this as-is or wait for additional test coverage.
|
|
@rursprung I merged this PR since its up to the cluster admin to write the DLS clause on each role, but I do think we should expand the coverage in this area. FYI DLS is adaptive by default. Take a look at which controls the flow of what adaptive means. DLS can be at the filter level (modify the query) or applied on the Lucene level. |
Description
OpenSearch introduced the possibility to use a
queryrather than justan
idin Terms Lookup Queries in opensearch-project/OpenSearch#18195 in release 3.2.0.However, support for this was never added to the security plugin for
DLS/FLS.
When trying to use
querybased TLQ in a DLS this failed for tworeasons:
DlsFilterLevelActionHandlerunconditionally dereferenced
termsLookup().id(), which returnsnullfor query-based lookups.DocumentAllowListprivilege bypass only handledGetRequest, but query-based TLQ internally resolves viaSearchRequestand additionally uses aGetSettingsRequest, causingthe privileges evaluator to block the lookup even after the NPE is
fixed.
This commit adds proper support for
querybased TLQ in DLS, both forthe old and the new evaluator, by allowlisting a wildcard entry for the
whole index in question rather than a single document in case
queryisused. additionally,
SearchRequestandGetSettingsRequestare nowalso supported in
DocumentAllowList#isAllowed.Furthermore, the legacy
PrivilegesEvaluatorImpl#checkDocAllowListHeadernow delegates toDocumentAllowList#isAllowedsince the old method body was ahand-inlined copy of the same logic (parse header, check request);
delegating removes the duplication and picks up
SearchRequestsupportwithout repeating the new code.
Header parsing in
DocumentAllowList#isAllowedis now delegated toDocumentAllowList#getto centralise error handling.The wildcard allowlist pattern is already established for Dashboards
multi-tenancy and is scoped to the request's thread context, so it
cannot grant persistent or write access beyond the TLQ resolution.
Existing code with the wildcard has been migrated to use the new
constant to make it easier to find it.
additionally,
DlsTermLookupQueryV4EvaluatorTesthas been added (in a separate commit) to run the tests fromDlsTermLookupQueryTestalso against the new evaluator (this unearthed thatGetSettingsRequesthad to be whitelisted as well; the old evaluator didn't block this!).Issues Resolved
fixes #6243
Do these changes introduce new permission(s) to be displayed in the static dropdown on the front-end?
no
Testing
unit & integration testing + manual testing
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.